<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="demo1"></div>


    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>


    <script type="text/babel">
        // 创建组件
        function Persion(props){
            const {name, gender, age} = props
            return (
                <h2>
                    <li>姓名: {name}</li>
                    <li>性别: {gender}</li>
                    <li>年龄: {age}</li>
                </h2>
            )
        }

        //对props进行限制, React 15版本以后依赖 prop-types.js
        Persion.propTypes = {
            // 对名字限制必须是字符串类型,不能为空
            name: PropTypes.string.isRequired,
            gender: PropTypes.string,
            age: PropTypes.number,
            speak: PropTypes.func
        }
        //对props设置默认值
        Persion.defaultProps = {
            gender: '未知'
        }


        // 渲染组件到页面
        ReactDOM.render(<Persion name='zhang' age={18} />, document.getElementById('demo1'))
    </script>

</body>
</html>